Skip to main content

Overview

Multi-node training allows you to scale CLIP training across multiple machines, enabling training on massive datasets with large models. OpenCLIP supports multi-node training through both native PyTorch distributed (torchrun) and SLURM cluster management.
OpenCLIP has been battle-tested on clusters with up to 1024 A100 GPUs, demonstrating robust scalability for large-scale training.

Prerequisites

  • Multiple machines with GPUs connected via high-bandwidth network
  • Network configuration allowing inter-node communication
  • Shared filesystem accessible from all nodes (recommended)
  • SLURM cluster (for SLURM-based training) or manual node coordination

Multi-Node with torchrun

Basic Setup

The torchrun launcher supports multi-node training with minimal configuration. The key is specifying the master node’s address and the number of nodes.
Key Parameters:
  • --nproc_per_node=4: Number of GPUs per node (4 in this example)
  • --nnodes=2: Total number of nodes
  • --node_rank=$NODE_RANK: Rank of current node (0 for master, 1, 2, … for workers)
  • --rdzv_endpoint=$MASTER_ADDR:$MASTER_PORT: Address of the master node

Environment Variables

Set these environment variables on each node: Master Node (Node 0):
Worker Nodes (Node 1, 2, …):

Complete Multi-Node Example

Here’s a complete example with 2 nodes, 4 GPUs each: On Master Node (192.168.1.10):
On Worker Node (192.168.1.11):

SLURM-Based Training

SLURM is the recommended approach for large-scale cluster training. It automatically handles node allocation, environment setup, and process launching.

Basic SLURM Script

SLURM Parameters:
  • --nodes=32: Number of nodes to allocate
  • --gres=gpu:4: Request 4 GPUs per node
  • --ntasks-per-node=4: Launch 4 tasks (1 per GPU) per node
  • --cpus-per-task=6: Allocate 6 CPU cores per task (for data loading)
  • --wait-all-nodes=1: Wait for all nodes to be ready before starting

Production SLURM Example

Here’s a production-ready SLURM script for training ViT-L/14 on LAION-400M:

Submitting SLURM Jobs

Network Configuration

Firewall Settings

Ensure communication ports are open between nodes:

Network Backend

Configure the distributed backend for your hardware: NVIDIA GPUs with NCCL (recommended):
Ascend NPU:
CPU-only:

InfiniBand Optimization

For clusters with InfiniBand, optimize NCCL settings:

Distributed Training Optimizations

Memory-Efficient Distributed Loss

For multi-node training, use these flags to reduce memory usage from O(n²) to O(n):
Without these flags:
  • Memory usage: O(batch_size × num_gpus)²
  • Example: 256 batch size × 128 GPUs = 8GB+ logit matrix
With these flags:
  • Memory usage: O(batch_size × num_gpus)
  • Same numerical results
  • Essential for large-scale training (64+ GPUs)
See Distributed Training for detailed explanation.

Gradient Accumulation

Simulate larger batch sizes across nodes:
Effective batch size:

Remote Checkpoint Syncing

For multi-node training, sync checkpoints to remote storage (S3, shared filesystem):
Parameters:
  • --logs: Local checkpoint directory
  • --remote-sync: Remote path (s3:// or shared filesystem path)
  • --remote-sync-frequency 300: Sync every 300 seconds (5 minutes)
  • --delete-previous-checkpoint: Save disk space on local nodes

Resume from Remote Checkpoint

SLURM Job Management

Interactive SLURM Session

For debugging, request interactive session:

Monitor Job Progress

Troubleshooting Multi-Node Training

Nodes Can’t Communicate

Symptom: Training hangs at initialization Solutions:
  1. Check firewall settings
  2. Verify MASTER_ADDR is reachable from all nodes:
  3. Check SLURM node allocation:

NCCL Initialization Errors

Symptom:
Solutions:
  1. Enable NCCL debugging:
  2. Check GPU visibility:
  3. Verify InfiniBand configuration (if applicable)

Inconsistent Results Across Nodes

Symptom: Different nodes show different loss values Solutions:
  1. Ensure same code version on all nodes
  2. Check data is accessible from all nodes
  3. Verify --seed is set for reproducibility
  4. Use --wait-all-nodes=1 in SLURM

Out of Memory on Some Nodes

Symptom: OOM error on specific nodes Solutions:
  1. Check GPU memory is equal across nodes:
  2. Use --grad-checkpointing for memory efficiency
  3. Reduce --batch-size per GPU
  4. Enable --local-loss --gather-with-grad

Performance Optimization

Network Bandwidth

Monitor network usage during training:
Target: High utilization during gradient synchronization

Scaling Efficiency

Measure scaling efficiency:
Tips for better scaling:
  • Use --local-loss --gather-with-grad
  • Ensure sufficient batch size per GPU (128-512)
  • Use WebDataset format
  • Optimize --workers for data loading

Benchmark Multi-Node Performance

Example: Large-Scale Training Configuration

Training ViT-H/14 on LAION-2B with 256 GPUs (64 nodes × 4 GPUs):

Next Steps

Distributed Training

Learn about advanced distributed training techniques

Configuration

Explore all training configuration options

Single-Node Training

Start with single-node training before scaling

Data Preparation

Prepare large-scale datasets for multi-node training